<template>
  <div class="photoinfo">
    <header>
      <h1 class="title">{{photoinfo.title}}</h1>
      <div class="btn-group">
        <span class="add_time">{{photoinfo.add_time}}</span>
        <span>点击{{photoinfo.click}}次</span>
      </div>
      <hr />
    </header>
    <div class="content">
      <div class="img-box">
        <img 
        v-for="(thum,index) in thums" :src="thum.src" 
        @click="showImage(index)"
        :key="thum.id"/>
      </div>
      <p>{{photoinfo.content}}</p>
    </div>
    <comment :id="id"></comment>
  </div>
</template>

<script >
import Comment from '@/components/Comment'
export default {
  data: () => ({
    id: 0,
    photoinfo: {},
    thums: []
  }),
  components: {
    Comment
  },

  created() {
    this.id = this.$route.params.id
    this.getimageInfo(), this.getthumimages()
  },

  methods: {
    async getimageInfo() {
      const {
        data: { status, message }
      } = await this.$axios.get('api/getimageInfo/' + this.id)
      if (status !== 0) this.$Toast(message)
      this.photoinfo = message
    },
    async getthumimages() {
      const {
        data: { status, message }
      } = await this.$axios.get('api/getthumimages/' + this.id)
      if (status !== 0) this.$Toast(message)
      this.thums = message
      console.log(message)
    },
    showImage(startPosition) {
      let images = []
      this.thums.forEach(item => {
        if (item.src) images.push(item.src)
      })
      this.$ImagePreview({
        images,
        startPosition
      })
    }
  }
}
</script>
<style lang="less" scoped>
header {
  padding: 8px;
  .title {
    font-size: 16px;
    color: red;
  }
  .btn-group {
    display: flex;
    justify-content: space-between;
    span {
      font-size: 12px;
    }
    .add_time {
      color: blue;
    }
  }
}
.content {
  line-height: 24px;
  font-size: 14px;
  text-align: justify;
  padding: 0px 2px;
}
.img-box {
  display: flex;
  justify-content: space-around;
  // align-items: center;
  // padding:1px 2px;
  img {
    height: 82px;
    // width: 100px;
  }
}
h1{
  text-align: center;
}
</style>
